{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Basic DEA functions examples\n",
    "\n",
    "在此示範如何使用CRS()、VRS()函式，並顯示執行後的結果。\n",
    "<br><br>\n",
    "※示範程式碼及csv資料存放於[這裡](https://github.com/wurmen/DEA/tree/master/Functions/basic_DEA_data%26code)，可自行下載測試。\n",
    "\n",
    "---------------------------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import DEA  #載入存放DEA函式的py檔(在此檔名為\"DEA.py\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## § CRS()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "- 先讀取資料，取得DMU列表，以及產出(Y)投入(X)資料，以利主函式使用\n",
    "- 假設產出與投入資料放於同個csv檔，因此使用csv2dict()函式，並指定2、4行為投入，5、8行為產出\n",
    "- 使用原問題投入導向的CRS model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "DMU,X,Y=DEA.csv2dict(\"data.csv\",in_range=[2,4],out_range=[5,8],assign=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The efficiency of DMU A:0.902\n",
      "The efficiency of DMU B:0.833\n",
      "The efficiency of DMU C:0.904\n",
      "The efficiency of DMU D:0.415\n",
      "The efficiency of DMU E:0.809\n",
      "The efficiency of DMU F:0.964\n",
      "The efficiency of DMU G:1.000\n",
      "The efficiency of DMU I:1.000\n",
      "The efficiency of DMU J:1.000\n",
      "The efficiency of DMU K:0.530\n",
      "The efficiency of DMU L:1.000\n",
      "The efficiency of DMU M:1.000\n",
      "The efficiency of DMU O:0.756\n"
     ]
    }
   ],
   "source": [
    "DEA.CRS(DMU, X, Y, orientation=\"input\", dual=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 產出與投入資料放至於不同的csv檔，因此使用csv2dict_sep()進行讀檔。<br>\n",
    "\n",
    "- 使用對偶模式的投入導向CRS model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "DMU, X=DEA.csv2dict_sep(\"example2_input.csv\")\n",
    "DMU, Y=DEA.csv2dict_sep(\"example2_output.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The efficiency of DMU Taiwan Fire:0.984\n",
      "The efficiency of DMU Chung Kuo:1.000\n",
      "The efficiency of DMU Tai Ping:0.988\n",
      "The efficiency of DMU China Mariners:0.488\n",
      "The efficiency of DMU Fubon:1.000\n",
      "The efficiency of DMU Zurich:0.594\n",
      "The efficiency of DMU Taian:0.470\n",
      "The efficiency of DMU Ming Tai:0.415\n",
      "The efficiency of DMU Central:0.327\n",
      "The efficiency of DMU the first:0.781\n",
      "The efficiency of DMU Kuo Hua:0.283\n",
      "The efficiency of DMU Union:1.000\n",
      "The efficiency of DMU Shing kong:0.353\n",
      "The efficiency of DMU South China:0.470\n",
      "The efficiency of DMU CathayCentury:0.979\n",
      "The efficiency of DMU Allianz President:0.472\n",
      "The efficiency of DMU Newa:0.635\n",
      "The efficiency of DMU AIU:0.427\n",
      "The efficiency of DMU North America:0.822\n",
      "The efficiency of DMU Federal:0.935\n",
      "The efficiency of DMU Royal&Sunalliance:0.333\n",
      "The efficiency of DMU Asia:1.000\n",
      "The efficiency of DMU AXA:0.599\n",
      "The efficiency of DMU Mitsui Sumitomo:0.257\n"
     ]
    }
   ],
   "source": [
    "DEA.CRS(DMU, X, Y, orientation=\"input\", dual=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## § VRS()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 假設產出與投入資料放於同個csv檔，因此使用csv2dict()函式，並指定2、4行為投入，5、8行為產出\n",
    "- 使用原問題投入導向的VRS model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "DMU,X,Y=DEA.csv2dict(\"data.csv\",in_range=[2,4],out_range=[5,8],assign=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The efficiency of DMU A:1.000\n",
      "The efficiency of DMU B:1.000\n",
      "The efficiency of DMU C:1.000\n",
      "The efficiency of DMU D:0.735\n",
      "The efficiency of DMU E:0.848\n",
      "The efficiency of DMU F:1.000\n",
      "The efficiency of DMU G:1.000\n",
      "The efficiency of DMU I:1.000\n",
      "The efficiency of DMU J:1.000\n",
      "The efficiency of DMU K:0.876\n",
      "The efficiency of DMU L:1.000\n",
      "The efficiency of DMU M:1.000\n",
      "The efficiency of DMU O:0.776\n"
     ]
    }
   ],
   "source": [
    "DEA.VRS(DMU, X, Y, orientation=\"input\", dual=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 產出與投入資料放於不同的csv檔，因此使用csv2dict_sep()函式進行讀取，將產出與投入資料轉成所需格式\n",
    "- 使用原問題產出導向的VRS model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "DMU, X=DEA.csv2dict_sep(\"data_input.csv\")\n",
    "DMU, Y=DEA.csv2dict_sep(\"data_output.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The efficiency of DMU A:1.000\n",
      "The efficiency of DMU B:1.000\n",
      "The efficiency of DMU C:1.000\n",
      "The efficiency of DMU D:0.493\n",
      "The efficiency of DMU E:0.876\n",
      "The efficiency of DMU F:1.000\n",
      "The efficiency of DMU G:1.000\n",
      "The efficiency of DMU I:1.000\n",
      "The efficiency of DMU J:1.000\n",
      "The efficiency of DMU K:1.000\n",
      "The efficiency of DMU L:1.000\n",
      "The efficiency of DMU M:1.000\n",
      "The efficiency of DMU O:1.000\n"
     ]
    }
   ],
   "source": [
    "DEA.VRS(DMU, X, Y, orientation=\"output\", dual=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
